public class Solution1283 {
    public int smallestDivisor(int[] nums, int threshold) {
        int l=1,r=Integer.MAX_VALUE,ans=-1;
        while (l<=r){
            int mid=l+(r-l)/2;
            int t=0;
            for (int num : nums) {
                t+=div(num,mid);
            }
            if (t<=threshold){
                ans=mid;
                r=mid-1;
            }else {
                l=mid+1;
            }
        }
        return ans;
    }

    private int div(int a, int b) {
        return a%b==0?a/b:a/b+1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1283().smallestDivisor(new int[]{1,2,5,9},6));
    }
}
